

// 每一个reducder 有自己的一套state 数据 和自己的一个操作state 数据的reduce函数
const defaultShopState = {
    shopArr: [{
        id: 1,
        proname: '华为笔记本-mate14'
    }, {
        id: 2,
        proname: '联想笔记本-B480'
    }],
    count: 100
}

// 定义购物车的reducer
const shopReducer = (state = defaultShopState, actions) => {
    if (actions.type == 'addgoods') {
        // 将state 原数据push 新对象
        state.shopArr.push(actions.payload)
        return {
            ...state,
            shopArr: state.shopArr
        }

    }
    if (actions.type == '+') {
        // 将state 原数据push 新对象
        return {
            ...state,
            count: state.count + actions.payload
        }

    }
    return state
}

export default shopReducer
